package com.neulogistics.core.customercenter.api.application.converter;

import cn.hutool.json.JSONUtil;
import com.neulogistics.core.customercenter.api.application.viewmodel.CustomerViewModel;
import com.neulogistics.core.customercenter.domain.model.valueobject.Address;
import com.neulogistics.core.customercenter.infrastructure.persistence.orm.po.CustomerPO;
import org.springframework.beans.BeanUtils;

public class CustomerPOVMConverter {
    public static CustomerViewModel POToVM(CustomerPO po){
        if(po == null)
            return null;

        CustomerViewModel viewModel = new CustomerViewModel();
        BeanUtils.copyProperties(po, viewModel);
        viewModel.setReceiverAddress(JSONUtil.toBean(po.getReceiverAddress(), Address.class));
        return viewModel;
    }
}
